package com.gjy.pd.deletage;

import java.util.concurrent.ThreadLocalRandom;

/**
 * @author 宫静雨
 * @version 1.0
 * @since 2023-01-16 16:25:15
 */
public class Client {

    public static void main(String[] args) {
        new Delegate().doTask();
    }

    interface ITask {
        void doTask();
    }

    private static class ConA implements ITask {

        @Override
        public void doTask() {
            System.out.println("A");
        }
    }

    private static class ConB implements ITask {

        @Override
        public void doTask() {
            System.out.println("B");
        }
    }

    private static class Delegate implements ITask {

        @Override
        public void doTask() {
            System.out.println("start");
            ITask task;
            if (ThreadLocalRandom.current().nextBoolean()) {
                task = new ConA();
            } else {
                task = new ConB();
            }
            task.doTask();
            System.out.println("end");
        }
    }
}
